package com.myspring.resttest.dao.impl.virtualmachine;

import javax.transaction.Transactional;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.myspring.resttest.dao.virtualmachine.VirtualMachineDaoInt;
import com.myspring.resttest.model.VirtualMachine.VirtualMachineAnnotation;


@EnableTransactionManagement
@Service
@Transactional

public class VirtualMachineDaoImpl implements VirtualMachineDaoInt{
	
	@Autowired
	SessionFactory	sessionFactory;

	@Override
	public void insertVirtualMachine(VirtualMachineAnnotation virtualMachine) {
		sessionFactory.getCurrentSession().save(virtualMachine);
	}

	@Override
	public VirtualMachineAnnotation getVirtualMachone(String virtualMachineName) {
		Query query = sessionFactory.getCurrentSession().createQuery(
				"from VirtualMachineAnnotation where vmname = :virtualMachineName");
		query.setParameter("virtualMachineName", virtualMachineName);
		return (VirtualMachineAnnotation) query.list().get(0);
	}

}
